<?php

class Application_Form_SubForm_AutoComplete extends ZendX_JQuery_Form {

    public function __construct($options) {

        parent::__construct();

        $this->setAttribs(array(
            'id' => 'formAutocomplete',
            'class' => 'span4 margin-bottom'));

        $this->setDecorators(array('FormElements', 'Form')); // supprime la balise <dl>

        $formJQueryElements = array(
            array('UiWidgetElement', array('tag' => 'div')), // pour les éléments jQuery
            array('HtmlTag', array('tag' => 'div')));


        $auto = new ZendX_JQuery_Form_Element_AutoComplete('aComplete');
        $auto->setRequired(false)
                ->setDecorators($formJQueryElements)
                ->setFilters(array('StripTags'))
                ->setAttribs(array('class' => 'span4', 'placeholder' => 'Recherche ...'))
                ->setJQueryParams(array(
                    'source' => $options['source'],
                    'minLength' => '1', // input minimum length charactere to search
                    'select' => new Zend_Json_Expr('function( event, ui ){
                            if(ui.item.href){document.location = ui.item.href}; return false;}'),
                    'close' => new Zend_Json_Expr('function( event, ui ){
                               $("#aComplete").val("");return false;}')
                ));

        $this->addElement($auto);
    }

}